home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: Is this a C BUG??? (A string issue)
- Date: 1 Apr 96 02:11:56 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.828324716@rscernix>
- References: <4jknpf$9k3@abel.cc.sunysb.edu>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <4jknpf$9k3@abel.cc.sunysb.edu> ghauser@ic.sunysb.edu (George Hauser) writes:
-
- >I am reading the whole line in one shot using fgets(). I need to pad with
- >blank spaces those records that are < 194, until the string is set to 194.
- >
- >Sometimes my records are already filled with 194 and sometimes not.
- >
- >When I get the string of a line that contains 195 chars (data + eoln) it
- >returns a line of 193 and then the next line returns 2 characters....
-
- This is correct.
-
- >This is WRONG fgets should return 194 characters...
-
- Before making a complete fool of yourself, read the description of the
- function fgets in your C book. You'll see, then, who is WRONG :-)
-
- >If someone sees something wrong with the code, I'd appreciate the advice.
- >But I think this is some obscure messed up hidden character.
- >
- >Here's the buggy code.
- >-----------------
- >
- >#define linemax 194 /* The predifined lenght of the record */
- >
- >void main(int argc, char *argv[])
-
- You haven't read the FAQ, have you?
-
- >{
- > FILE *sourcefp, *destfp; /*Source and destination pointers */
- > char line[linemax + 1]; /* The lenght of the line plus NULL terminator */
- > long int records; /* Number of records that can be passed to ext */
- >
- > records = 0;
- > while(fgets(line,linemax,sourcefp) != NULL)
- ^^^^^^^
- This should be linemax + 1.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-